package com.eduagent.xwqeduagent.utils.oj;

/**
 * Judge0评测状态码常量
 */
public class JudgeStatusCode {

    // 处理状态
    public static final int IN_QUEUE = 1;                   // 在队列中
    public static final int PROCESSING = 2;                 // 处理中
    
    // 完成状态
    public static final int ACCEPTED = 3;                   // 通过
    public static final int WRONG_ANSWER = 4;               // 答案错误
    public static final int TIME_LIMIT_EXCEEDED = 5;        // 时间超限
    public static final int COMPILATION_ERROR = 6;          // 编译错误
    public static final int RUNTIME_ERROR_SIGSEGV = 7;      // 运行时错误 (SIGSEGV)
    public static final int RUNTIME_ERROR_SIGXFSZ = 8;      // 运行时错误 (SIGXFSZ)
    public static final int RUNTIME_ERROR_SIGFPE = 9;       // 运行时错误 (SIGFPE)
    public static final int RUNTIME_ERROR_SIGABRT = 10;     // 运行时错误 (SIGABRT)
    public static final int RUNTIME_ERROR_NZEC = 11;        // 运行时错误 (NZEC)
    public static final int RUNTIME_ERROR_OTHER = 12;       // 其他运行时错误
    public static final int INTERNAL_ERROR = 13;            // 内部错误
    public static final int EXEC_FORMAT_ERROR = 14;         // 执行格式错误
    
    // 附加状态
    public static final int MEMORY_LIMIT_EXCEEDED = 15;     // 内存超限
    
    /**
     * 判断是否处于排队或处理中状态
     * 
     * @param statusId 状态ID
     * @return 是否处于等待状态
     */
    public static boolean isPending(Integer statusId) {
        return statusId != null && (statusId == IN_QUEUE || statusId == PROCESSING);
    }
    
    /**
     * 判断是否已完成状态
     * 
     * @param statusId 状态ID
     * @return 是否已完成
     */
    public static boolean isCompleted(Integer statusId) {
        return statusId != null && statusId >= ACCEPTED;
    }
    
    /**
     * 判断是否成功状态
     * 
     * @param statusId 状态ID
     * @return 是否成功
     */
    public static boolean isSuccess(Integer statusId) {
        return statusId != null && statusId == ACCEPTED;
    }
    
    /**
     * 判断是否运行时错误
     * 
     * @param statusId 状态ID
     * @return 是否运行时错误
     */
    public static boolean isRuntimeError(Integer statusId) {
        return statusId != null && (
            statusId == RUNTIME_ERROR_SIGSEGV || 
            statusId == RUNTIME_ERROR_SIGXFSZ || 
            statusId == RUNTIME_ERROR_SIGFPE || 
            statusId == RUNTIME_ERROR_SIGABRT || 
            statusId == RUNTIME_ERROR_NZEC || 
            statusId == RUNTIME_ERROR_OTHER
        );
    }
    
    /**
     * 获取状态描述
     * 
     * @param statusId 状态ID
     * @return 状态描述
     */
    public static String getStatusDescription(Integer statusId) {
        if (statusId == null) {
            return "未知状态";
        }
        
        switch (statusId) {
            case IN_QUEUE: return "排队中";
            case PROCESSING: return "处理中";
            case ACCEPTED: return "通过";
            case WRONG_ANSWER: return "答案错误";
            case TIME_LIMIT_EXCEEDED: return "时间超限";
            case COMPILATION_ERROR: return "编译错误";
            case RUNTIME_ERROR_SIGSEGV: return "运行时错误 (SIGSEGV)";
            case RUNTIME_ERROR_SIGXFSZ: return "运行时错误 (SIGXFSZ)";
            case RUNTIME_ERROR_SIGFPE: return "运行时错误 (SIGFPE)";
            case RUNTIME_ERROR_SIGABRT: return "运行时错误 (SIGABRT)";
            case RUNTIME_ERROR_NZEC: return "运行时错误 (NZEC)";
            case RUNTIME_ERROR_OTHER: return "其他运行时错误";
            case INTERNAL_ERROR: return "内部错误";
            case EXEC_FORMAT_ERROR: return "执行格式错误";
            case MEMORY_LIMIT_EXCEEDED: return "内存超限";
            default: return "未知状态 (" + statusId + ")";
        }
    }
} 